<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
//修改模块
class Tmpmanage extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('fuc');
        $this->load->library('topclass');
        $this->load->database();
        $this->load->model('memmbers');
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
		decis_last_time();
    }
	
	public function genarray($usernick) {//这步生成数组
        $resp = $this->topclass->api_getSellercatsListGetRequest("SellercatsListGetRequest", $usernick, $sessionkey = null);
        objectToArray(&$resp);
        return $resp;
    }
	
    public function index() {
        $data['menu'] = 'manage';
        $data['userleve'] = $this->memmbers->get_user_level();
        $data["tmpresarray"] = get_tmpres($_SESSION["shopid"]);

        $this->load->view('header_view', $data);
        $this->load->view('tmpmanage_view');
        $this->load->view('footer_view');
    }

    public function del() {
        if ($this->uri->segment(3) === FALSE) {
            $id = 0;
            redirect("tmpmanage");
        } else {
            $id = $this->uri->segment(3);
            if (!is_numeric($id)) {
                redirect("tmpmanage");
            }
        }
        $sql = "delete from  res where id ={$id }";
        $this->db->query($sql);
        redirect("tmpmanage");
    }

    public function edit() {
		$data['menu'] = 'manage';
        if ($this->uri->segment(3) === FALSE) {
            $id = 0;
            redirect("tmpmanage");
        } else {
            $id = $this->uri->segment(3);
            if (!is_numeric($id)) {
                redirect("tmpmanage");
            }
        }
        $data['redirectudl'] = site_url("tmpmanage");
        $data['id'] = $id;
        $data['userleve'] = $this->memmbers->get_user_level();
		$this->load->view('header_view', $data);
        $this->load->view('tmpedit_view');
        $this->load->view('footer_view');

        //redirect("tmpmanage");
    }

    public function template_edit($id = '') {
        $sql = 'select * from res where id=' . $id;
        $r = $this->db->query($sql);
        $arr = $r->row_array();
        if (empty($arr)) {
            $data['redirectudl'] = site_url("tmpmanage");
            echo "<script LANGUAGE=\"JavaScript\">
         window.parent.location=\"{$data['redirectudl']}\";

</script> ";

            exit;
        }

        $tmpcssarray = explode("/", $arr['tmpath']);
        $data['content'] = htmlspecialchars_decode($arr['content']);

        $data['moduleType'] = $tmpcssarray[0];
        $data['modl_name'] = $tmpcssarray[1];
        $data['tmpname'] = $arr['tmpname'];
        $data['tmpid'] = $id;
        $data['redirectudl'] = site_url("tmpmanage");
		
		if($data['moduleType'] == 'wangwang'){
			$data['wangwang'] = generatewanwagarray($_SESSION["shopid"]);
			$data['wangwang_small'] = $data['wangwang'];
		}elseif($data['moduleType'] == 'category'){
			$data['rrr'] = $this->genarray($_SESSION["usernick"]);
			$sellarray = $data['rrr']["seller_cats"]["seller_cat"];
			$data['test_cats'] =  chagearray2($sellarray);
		}else{
			$data['wangwang'] = generatewanwagarray($_SESSION["shopid"]);
			$data['wangwang_small'] = $data['wangwang'];
			$data['rrr'] = $this->genarray($_SESSION["usernick"]);
			$sellarray = $data['rrr']["seller_cats"]["seller_cat"];
			$data['test_cats'] =  chagearray2($sellarray);
		}
		$data['colors'] = f100colors();
        $this->load->view('template_view2', $data);
    }

    public function changesatues() {

        // print_r($_POST);
        $updatesql = "update res set staute=1 where id={$_POST["id"]}";
        $this->db->query($updatesql);
        $updatesql = "update res set staute=0 where id<>{$_POST["id"]} and shopid=\"{$_SESSION["shopid"]}\" and width={$_POST["width"]} ";
        $this->db->query($updatesql);
    }

    public function updatetmp() {

        //print_r($_POST);
        $htmlcontent = htmlspecialchars($_POST["htmlcontent"]);
        $tmpname = $_POST["tmpname"];
        $tmpid = $_POST["tmpid"];
        if (!is_numeric($tmpid)) {
            redirect("tmpmanage");
        }

        $updatsql = "update res set  tmpname=\"{$tmpname}\",content=\"{$htmlcontent}\" where 
 id={$tmpid}
 ";
        $this->db->query($updatsql);
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */